public class Offer17 {
    public void printToMaxDigits(int n){
        if (n<=0) return;
        if (n<=18){
            for (long i = 1; i < Math.pow(10,n); i++) {
                System.out.println(i);
            }
        }else {
            char[] number = new char[n];
            for (int i = 0; i < number.length; i++) {
                number[i]='0';
            }
            while (!canInc(number)){
                printNum(number);
            }
        }
    }

    public boolean canInc(char[] number){
        boolean overflow = false;
        int toUp = 0;
        int length = number.length;
        for (int i = length-1; i >=0 ; i--) {
            int nSum = number[i]-'0'+toUp;
            if (i==length-1) nSum++;
                if (nSum>=10){
                    if (i==0){
                        overflow=true;
                    }else {
                        nSum=nSum-10;
                        toUp=1;
                        number[i]=(char) ('0'+nSum);
                    }
                }else {
                    number[i]=(char) ('0'+nSum);
                    break;
                }
        }
        return overflow;
    }
    public void printNum(char[] number){
        int index=0;
        for (; index < number.length; index++) {
            if (number[index]!='0') break;
        }
        for (; index < number.length; index++) {
            System.out.print(number[index]);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        Offer17 offer17 = new Offer17();
        offer17.printToMaxDigits(17);
    }
}
